<template>
  <el-table
    :data="users"
    style="width: 100%">
    <el-table-column
      label="作者"
      width="180">
      <template slot-scope="scope">
        <i class="el-icon-user-solid"></i>
        <span style="margin-left: 10px">{{ scope.row.username }}</span>
      </template>
    </el-table-column>
    <el-table-column
      label="简介"
      width="180">
      <template slot-scope="scope">
        <el-popover trigger="hover" placement="top">
          <div slot="reference" class="name-wrapper">
            <el-tag size="medium">{{ scope.row.intro }}</el-tag>
          </div>
        </el-popover>
      </template>
    </el-table-column>
    <el-table-column
      label="性别"
      width="180">
      <template slot-scope="scope">
        <span style="margin-left: 10px">{{ scope.row.sex }}</span>
      </template>
    </el-table-column>
    <el-table-column
      label="年龄"
      width="180">
      <template slot-scope="scope">
        <span style="margin-left: 10px">{{ scope.row.age }}</span>
      </template>
    </el-table-column>
    <el-table-column
      label="生日"
      width="180">
      <template slot-scope="scope">
        <span style="margin-left: 10px">{{ scope.row.birthday }}</span>
      </template>
    </el-table-column>
    <el-table-column label="操作">
      <template slot-scope="scope">
        <el-button
          size="mini"
          type="danger"
          @click="handleDelete(scope.$index, scope.row)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
import axios from 'axios';
  export default {
    data() {
      return {
        users: []
      }
    },
    methods:{
      getUsers(){
        axios.get('http://localhost:8081/admin/allUser').then(
        res=>{
          console.log(res.data.data);
          this.users = res.data.data
        }
      )
      },
      handleDelete(index,row){
        console.log(index,row);
        axios.delete(`http://localhost:8081/admin/deleteuser/${row.uid}`).then(
          res=>{
            console.log(res.data.state);
            if (res.data.state === 200) {
              alert("删除用户成功")
              this.getUsers()
            }
          }
        )
      }
    },
    mounted(){
      this.getUsers()
    }
    
  }
</script>